package cn.com.qingz.modules.user.service.impl;

import cn.com.qingz.core.utils.StringUtil;
import cn.com.qingz.modules.system.service.Identity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.github.miemiedev.mybatis.paginator.domain.PageList;
import cn.com.qingz.modules.system.service.impl.GeneralServiceImpl;
import cn.com.qingz.modules.user.mapper.*;
import cn.com.qingz.modules.user.model.*;
import cn.com.qingz.modules.user.service.*;
import cn.com.qingz.modules.user.vo.*;
import tk.mybatis.mapper.entity.Example;

import java.util.Arrays;
import java.util.List;

@Service
public class SampleHouseServiceImpl extends GeneralServiceImpl<SampleHouse> implements SampleHouseService {

    @Autowired
    private SampleHouseMapper samplehouseMapper;

    @Autowired
    private ModelMapper modelMapper ;



    public PageList<SampleHouse> queryForPage(Object condition, int page, int limit) {

        PageList<SampleHouse> list =  samplehouseMapper.queryForPage((SampleHouseSearchCondition) condition, new PageBounds(page, limit));
        for (SampleHouse sampleHouse : list) {
            String models = sampleHouse.getModels();
            if(StringUtil.isNotEmpty( models)){
                String ids []= models.split(",");
                if( ids != null){
                    List<Model>  modellists = modelMapper.getByIdList(Arrays.asList(ids)) ;
                    sampleHouse.setModelsList(modellists);
                }

            }
        }
        return list;
    }

    public void doAddOrUpdate(SampleHouse t) {
        Long id = t.getId();
        if (id == null) {
            mapper.insert(t);
        } else {
            mapper.updateByPrimaryKeySelective(t);
        }
    }

}
